<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    style="top:50px"
    cancelText="关闭">

    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="名称">
                <a-input placeholder="请输入名称" v-model="queryParam.materialName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->
      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          class="j-table-force-nowrap"
          :scroll="{x:true}"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @change="handleTableChange"/>
      </div>
    </a-card>

  </j-modal>
</template>
<script>
import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import { getAction } from '@api/manage'


export default {
  name: 'ErpGoodsListModel',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  // props: ['category', "modalWidth",],
  props: {
    category: {
      type: String
    },
    modalWidth: {
      type: Number,
      required: false,
      default: 1250
    },
    checkval: {
      type: String,
      default: 'radio'
    },
    supplierId: {
      type: String,
      required: false
    }
  },
  watch: {
    category(newValue) {
      // 当category变更时，可以进行一些处理
      console.log('Category changed to:', newValue);
      this.queryParam = {id: newValue};
      this.loadData();
    }
  },
  data() {
    return {
      description: '入库信息管理页面',
      visible: false,
      title: '选择物料',
      disableMixinCreated: true,
      queryParam: {categoryCode: this.category},
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:60,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title:'物料编号',
          align:"center",
          dataIndex: 'materialCode'
        },
        {
          title:'客户物料编号',
          align:"center",
          dataIndex: 'customerMaterialNo'
        },
        {
          title:'物料名称',
          align:"center",
          dataIndex: 'materialName'
        },
        {
          title:'规格型号',
          align:"center",
          dataIndex: 'spec'
        },
        {
          title:'主单位',
          align:"center",
          dataIndex: 'unit_dictText'
        },
        {
          title: '批次号',
          dataIndex: 'lotNumber',
          align:"center",
        },
        {
          title: '物料批号',
          dataIndex: 'materialLotNum',
          align:"center",
        },
        {
          title: '库位',
          dataIndex: 'storehouse',
          align:"center",
        },
        {
          title: '入库数量',
          dataIndex: 'num',
          align:"center",
        },
        {
          title: '入库单号',
          dataIndex: 'code',
          align:"center",
        },
        {
          title: '入库日期',
          dataIndex: 'storageDate',
          align:"center",
        },
        {
          title: '限用日期',
          dataIndex: 'expiryDate',
          align:"center",
        },
        {
          title: '供应商',
          dataIndex: 'supplierName',
          align:"center",
        },
        {
          title: '生产车间',
          dataIndex: 'workshop',
          align:"center",
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          align:"center",
        },
      ],
      url: {
        list: "/org.jeecg.modules.business/bussStorage/queryDetailForOutbound",
        delete: "/inventory/bussInventory/delete",
        deleteBatch: "/inventory/bussInventory/deleteBatch",
        exportXlsUrl: "/inventory/bussInventory/exportXls",
        importExcelUrl: "inventory/bussInventory/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    handleSubmit() {
      this.getGoodsSelectRows();
      this.searchReset(false)
      this.onClearSelected();
      this.close();
    },
    add() {
      this.showModal();
    },
    showModal() {
      this.dataSource = []
      this.visible = true;
      this.loadData();
    },
    getGoodsSelectRows() {
      let selectedRow = null;
      if(this.checkval=='radio'){
         selectedRow = this.selectionRows[0];
      }else{
         selectedRow = this.selectedRowKeys
      }
      // let selectedRow = this.selectionRows[0];
      //传递选中的数据
      this.$emit("inboundOk", selectedRow);
    },
    initDictConfig() {
    },
    close() {
      this.searchReset(false);
      this.visible = false;
    },
    getSuperFieldList() {
      let fieldList = [];

      fieldList.push({type:'string',value:'materialCode',text:'物料编号',dictCode:''})
      fieldList.push({type:'string',value:'materialName',text:'物料名称',dictCode:''})
      fieldList.push({type:'string',value:'customerMaterialNo',text:'客户物料编号',dictCode:''})
      fieldList.push({type:'string',value:'spec',text:'规格型号',dictCode:''})
      fieldList.push({type:'string',value:'unit',text:'主计量单位',dictCode:'ji_unit'})
      fieldList.push({type:'string',value:'materialLotNum',text:'物料批号',dictCode:''})
      fieldList.push({type:'string',value:'lotNumber',text:'批次号',dictCode:''})
      fieldList.push({type:'string',value:'storehouse',text:'库位',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'num',text:'入库数量',dictCode:''})
      fieldList.push({type:'string',value:'code',text:'入库单号',dictCode:''})
      fieldList.push({type:'string',value:'storageDate',text:'入库日期',dictCode:''})
      fieldList.push({type:'string',value:'expiryDate',text:'限用日期',dictCode:''})
      fieldList.push({type:'string',value:'supplier',text:'供应商',dictCode:''})
      fieldList.push({type:'string',value:'workshop',text:'生产车间',dictCode:''})
      fieldList.push({type:'string',value:'customerName',text:'客户名称',dictCode:''})
      this.superFieldList = fieldList
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!")
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      var params = this.getQueryParams();//查询条件
      params.supplierId = this.supplierId;
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records || res.result;
          if (res.result.total) {
            this.ipagination.total = res.result.total;
          } else {
            this.ipagination.total = 0;
          }
          //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.loading = false
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>